package com.fyl.validation.aop;

import com.fyl.aop.AbstractControllerMethodPointcut;
import com.fyl.aop.RequestMappingMethodMatcher;
import com.fyl.validation.anno.ValidationParam;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

public class ValidationMatchingPointcut extends AbstractControllerMethodPointcut {

    public ValidationMatchingPointcut() {
        super(new RequestMappingMethodMatcher() {
            @Override
            public boolean matches(Method method, Class<?> targetClass) {
                if (super.matches(method, targetClass)) {
                    Parameter[] parameters = method.getParameters();
                    for (Parameter param : parameters) {
                        if (param.isAnnotationPresent(ValidationParam.class)) {
                            return true;
                        }
                    }
                }
                return false;
            }
        });
    }
}
